package short_semester.questionnaire_planet.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import short_semester.questionnaire_planet.pojo.ScoreOption;
import short_semester.questionnaire_planet.pojo.ScoreQuestion;

import javax.transaction.Transactional;
import java.util.List;

public interface ScoreOptionDao extends JpaRepository<ScoreOption,Integer> {
    public List<ScoreOption> findByScoreQuestionOrderBySequenceAsc(ScoreQuestion scoreQuestion);
    
    @Transactional
    @Modifying
    public void deleteByScoreQuestion(ScoreQuestion question);
    
    public List<ScoreOption> findByScoreQuestion(ScoreQuestion question);

    @Modifying
    @Transactional
    @Query("update ScoreOption o set o.count=o.count+1 where o.id=:id")
    void submitOption(Integer id);
}
